<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录页面 - 后台管理系统</title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <meta name="keywords" content="LightYear,后台模板,后台管理系统">
    <meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
    <link rel="stylesheet" href="./css/bootstrap.css">
    <!-- <link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" -->
    <link rel="stylesheet" href="./css/materialdesignicons.min.css">
    <link href="css/style.min.css" rel="stylesheet">
    <style>
        * {
            font-family: 'Courier New', Courier, monospace;
        }

        .topbar {
            background-color: #fff;
        }

        .content-left>div {
            width: 200px;
            height: 50px;
            text-align: center;
            line-height: 50px;
            font-weight: bold;
        }

        body {
            height: 100vh;
            overflow: hidden;
        }
        .xgpwsBox{
            position: fixed;
            top: 78px;
            right: -560px;
            width: 560px;
            height: 90vh;
            background-color: #fff;
            padding-top: 15vh;
            transition: all 0.5s linear;
        }
        .xgpwsBox>div{
            width: 300px;
            margin: 20px auto;
        }
    </style>
</head>

<body>
    <button type="button" class="btn btn-primary btn-lg tanchuang" data-toggle="modal" data-target="#myModal"
        style="display: none;">
        Launch demo modal
    </button>

    <!-- Modal -->
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">Modal title</h4>
                </div>
                <div class="modal-body">
                    ...
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-primary">Save changes</button>
                </div>
            </div>
        </div>
    </div>
    <div class="topbar">
        <div class="topbar-left">
            <!-- <div class="lyear-aside-toggler">
            <span class="lyear-toggler-bar"></span>
            <span class="lyear-toggler-bar"></span>
            <span class="lyear-toggler-bar"></span>
          </div> -->
            <span class="navbar-page-title" id="BiaoT">
                <img src="./1.PNG" alt=""> </span>
        </div>

        <ul class="topbar-right">
            <li class="dropdown dropdown-profile">
                <a href="javascript:void(0)" data-toggle="dropdown">
                    <img class="img-avatar img-avatar-48 m-r-10" src="favicon.ico" alt="" />
                    <span><span id="NaMe">光年</span> <span class="caret"></span></span>
                </a>
                <ul class="dropdown-menu dropdown-menu-right">
                    <!-- <li> <a href=""><i class="mdi mdi-account"></i> 个人信息</a> </li> -->
                    <li class="xgpws"> <a  onclick="xgpwstran()"><i class="mdi mdi-lock-outline"></i> 修改密码</a> </li>
                    <li class="pz"> <a href="javascript:void(0)" onclick="pz()"><i class="mdi mdi-delete"></i> 配置菜单</a></li>
                    <li class="divider"></li>
                    <li> <a href="./login.html"><i class="mdi mdi-logout-variant"></i> 退出登录</a> </li>
                </ul>
            </li>
        </ul>
    </div>
    <div class="content">
        <div class="content-left">

        </div>
        <div class="content-right">
            <iframe src="" width="100%" style="height: 90vh;" frameborder="0" id="iframe"></iframe>
        </div>
    </div>
    <div class="xgpwsBox">
        <div class="form-group has-feedback feedback-left">
            <input type="password" placeholder="请输入旧密码" class="form-control" id="formepassword" name="password" />
            <span class="mdi mdi-lock form-control-feedback" aria-hidden="true"></span>
        </div>
        <div class="form-group has-feedback feedback-left">
            <input type="password" placeholder="请输入新密码" class="form-control" id="newpassword" name="password" />
            <span class="mdi mdi-lock form-control-feedback" aria-hidden="true"></span>
        </div>
        <div class="form-group">
            <label class="lyear-checkbox checkbox-primary m-t-10">
            </label>
          </div>
        <div class="form-group">
            <button class="btn btn-block btn-primary" type="button" onclick="xgmm()">确定修改</button>
            <button class="btn btn-block btn-primary" type="button" onclick="quexgmm()">取消修改</button>
        </div>
    </div>

    <script src="./js/jquery.min.js"></script>
    <script src="./js/bootstrap.min.js"></script>
    <script src="./js/pubilc.js"></script>
    <script>
        var id;
        var arr = ['./page/专业.html', './page/nianji.html', './page/职级管理.html', './page/juese.html', './page/教师管理.html', './page/xuesheng.html']
        window.onload = function () {
            var token = sessionStorage.getItem('token')
            if (token) {
                xhr({
                    methods: 'get',
                    url: '/user/info',
                    header: {
                        token: token
                    },
                    success: function (res) {
                        console.log(res)
                        if (res.belong_to_school) {
                            console.log(res.belong_to_school)
                            // return
                            id = sessionStorage.setItem('id', res.belong_to_school)
                            NaMe.innerHTML = res.user_name
                            BiaoT.innerHTML = res.school_name
                            sX()
                        } else {
                            document.querySelector('.xgpws').style.display = 'none'
                            document.querySelector('.pz').style.display = 'none'
                            iframe.src = './page/cg.html'

                        }
                    }
                })
            } else {
                location.href = './login.html'
            }
            iframe.contentWindow.postMessage("Hellow", "*");
        }
        var content = document.getElementsByClassName('content')[0]
        var content_left = document.getElementsByClassName('content-left')[0]
        var content_right = document.getElementsByClassName('content-right')[0]
        function pz() {
            iframe.src = './page/配置菜单.html'
            // content_left.style.width = '200px'
            content_right.style.width = '100vw'
            // content.style.display = 'flex'
        }
        // window.addEventListener("message", function (event) {
        //     sX()
        // });
        function sX() {
            xhr({
                methods: 'get',
                url: `/rankSys/getFn?school_id=${Number(sessionStorage.getItem('id'))}`,
                success: function (res) {
                    console.log(res)
                    if (res.length < 1) {
                        content_left.style.display = 'none'
                        content_right.style.width = '100vw'
                        iframe.src = './login.html'
                    } else {
                        content.style.display = 'flex'
                        content_left.style.width = '200px'
                        content_right.style.width = 'calc(100vw - 200px)'
                        content_left.innerHTML = ''
                        iframe.src = arr[res[0].page_id - 1]
                        for (i = 0; i < res.length; i++) {
                            content_left.innerHTML += `<div onclick=a(${res[i].page_id - 1})>${res[i].page_name}</div>`
                        }
                    }
                }
            })

        }
        function a(i) {
            iframe.src = arr[i]
        }
        function xgmm(){
            if(formepassword.value && newpassword.value){
                xhr({
                    methods:'post',
                    url:'/user/editPassword',
                    data:JSON.stringify({
                        user_id:sessionStorage.getItem('id'),
                        old_password:formepassword.value,
                        new_password:newpassword.value
                    }),
                    success:function(res){
                        console.log(res)
                        location.replace('./login.html')
                    }
                })
            }else{
                document.querySelector('.tanchuang').click()
                document.querySelector('.modal-title').innerHTML = '请输入密码'
                document.querySelector('.modal-body').innerHTML = '请输入新旧密码'
                document.querySelector('.modal-footer').innerHTML = '<button type="button" class="btn btn-default" data-dismiss="modal">确定</button>'
            }
        }
        function quexgmm(){
            document.querySelector('.xgpwsBox').style.right = '-560px'
        }
        function xgpwstran(){
            
            document.querySelector('.xgpwsBox').style.right = '0'
        }
    </script>
</body>

</html>